<cfcomponent extends="net.sourceforge.cfunit.framework.TestCase">


  <cffunction name="setUp" returntype="void" access="public">
			<cfset serviceDefinitionLocation = expandPath( 'services.xml' ) />
			<cfset coldSpring = createObject( 'component', 'coldspring.beans.DefaultXmlBeanFactory').init() />
			<cfset coldSpring.loadBeansFromXmlFile("/actionpacks/cfsvn/config/cs/svnConfiguration.xml") />			
      <cfset variables.svnService = coldSpring.getBean('svnService') />
   </cffunction>


	<cffunction name="verifyRevisionInfo" returntype="string" access="private">
		<cfargument name="revisioninfo">
		<cfif (left(revisioninfo,1) eq "r")>
		  <cfreturn "revised">
		<cfelse>
			<cfreturn revisioninfo>
		</cfif>
	</cffunction>

	<cffunction name="addDirectory" returntype="any" access="public">
		<cfargument name="dir" default="/testdir">
	  <cfset var url = arguments.dir>
	  <cfset var commitMessage = "testing directory add">
	  <cfset var results = variables.svnService.createDirectory(url,commitMessage)>
		<cfreturn verifyRevisionInfo(results) />
	</cffunction>

	<cffunction name="addResource" returntype="any" access="public">
		<cfargument name="filename" default="test.txt">
	  <cfset var url = arguments.filename>
	  <cfset var commitMessage = "testing text file commit">
	  <cfset var fileData = "This is the test text for the file ARR">
	  <cfset var results = variables.svnService.addOrUpdateResource(url,commitMessage,fileData)>
		<cfreturn verifyRevisionInfo(results) />
	</cffunction>

	<cffunction name="deleteResource" returntype="any" access="public">
		<cfargument name="resource" required="true">
	  <cfset var url = arguments.resource>
	  <cfset var commitMessage = "testing resource delete">
	  <cfset var results = variables.svnService.deleteResource(url,commitMessage)>
		<cfreturn verifyRevisionInfo(results) />
	</cffunction>

	<cffunction name="testAddDeleteDirectory" returntype="void" access="public">
	  <cfset var results = addDirectory("/testdir")>
		<cfset var cleanupdir = deleteResource("/testdir") />
		<cfset assertEquals(expected="revised",actual=results) />
	</cffunction>

	<cffunction name="testAddDeleteResource" returntype="void" access="public">
	  <cfset var tmpdir = addDirectory("/tempdir") />
	  <cfset var tmpresource = addResource("/tempdir/tempfile.txt") />
	  <cfset var url = "/tempdir/tempfile.txt" />
	  <cfset var results = deleteResource(url)>
		<cfset var cleanupdir = deleteResource("/tempdir") />
		<cfset assertEquals(expected="revised",actual=results) />
	</cffunction>

	<cffunction name="testAddDeleteRenameResource" returntype="void" access="public">
	  <cfset var tmpdir = addDirectory("/tempdir") />
	  <cfset var tmpresource = addResource("/tempdir/tempfile.txt") />
	  <cfset var url = "/tempdir/tempfile.txt" />
	  <cfset var results = deleteResource(url)>
		<cfset var cleanupdir = deleteResource("/tempdir") />
		<cfset assertEquals(expected="revised",actual=results) />
	</cffunction>


	<cffunction name="testAddDeleteResourceRecursive" returntype="void" access="public">
	  <cfset var results = addResource("/tempdir/tempfolder/anotherfolder/tempfile.txt") />
	  <cfset var cleanup = deleteResource("/tempdir/tempfolder/anotherfolder/tempfile.txt")>
		<cfset cleanup = deleteResource("/tempdir/tempfolder/anotherfolder") />
		<cfset cleanup = deleteResource("/tempdir/tempfolder") />
		<cfset cleanup = deleteResource("/tempdir") />
		<cfset assertEquals(expected="revised",actual=results) />
	</cffunction>


	<cffunction name="testListResources" returntype="void" access="public">
	  <cfset var tmpdir = addDirectory("/tempdir") />
	  <cfset var tmpresource = addResource("/tempdir/tempfile.txt") />
	  <cfset var list = variables.svnService.List("/tempdir") />
	  <cfset var cleanupfile = deleteResource("/tempdir/tempfile.txt")>
		<cfset var cleanupdir = deleteResource("/tempdir") />
		<cfset assertEquals(expected="tempfile.txt",actual=valueList(list.path)) />
	</cffunction>

	<cffunction name="testExportResources" returntype="void" access="public">
	  <cfset var tmpdir = addDirectory("/tempdir") />
	  <cfset var tmpresource = addResource("/tempdir/tempfile.txt") />
	  <cfset var export = variables.svnService.export("/tempdir/cfsvnexports/test") />
	  <cfset var cleanupfile = deleteResource("/tempdir/tempfile.txt")>
		<cfset var cleanupdir = deleteResource("/tempdir") />
		<cfset assertEquals(expected="exported",actual=export) />
	</cffunction>
		
</cfcomponent>